package cn.cmvideo.ps;

import java.util.concurrent.TimeUnit;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class Runner implements CommandLineRunner
{
	private RabbitTemplate rabbitTemplate;
	private Receiver receiver;

	public Runner(RabbitTemplate rabbitTemplate, Receiver receiver)
	{
		this.rabbitTemplate = rabbitTemplate;
		this.receiver = receiver;
	}

	@Override
	public void run(String... args) throws Exception
	{
		System.out.println("sending message......");
		rabbitTemplate.convertAndSend(Application.TOPICEXCHANGENAME, "foo.bar.baz", "Hello from RabbitMQ!");
		receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
	}

}
